/*
 * Copyright 2010 Mttang.com All right reserved. This software is the confidential and proprietary information of
 * Mttang.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with Mttang.com.
 */
package com.mttang.util;

/**
 * 类StringUtils.java的实现描述：字符串处理类实现
 * 
 * @author huangbin 2010-6-22 下午08:38:38
 * 
 * @checkItem Add-YouLong-2011-06-09 
 *            {@link #isEmpty(String)}
 *            {@link #objToString(Object)}
 *            {@link #trim(String)}
 *            {@link #trimToNull(String)}
 */
public class StringUtils {

    /**
     * 验证数字
     * 
     * @param param
     * @return
     */
    public static boolean isLegalNumber(String param) {
        String pattern = "^([0-9])*$";
        if (param != null && param.trim().length() > 0 && param.matches(pattern)) {
            return true;
        }
        return false;
    }

    /**
     * 验证字符串
     * 
     * @param param
     * @return
     */
    public static boolean isLegalString(String param) {
        if (param != null && param.trim().length() > 0) {
            return true;
        }
        return false;
    }
    
    /**
     * 验证空对象，转换为字符串
     * 
     * @param str
     * @return
     */
    public static String objToString(Object str)
    {
      return str == null || str.toString().equals("null") ? "" : str.toString();
    }
    
    /**
     *字符串去空格
     * 
     * @param str
     * @return
     */
    public static String trim(String str)
    {
      return str == null ? null : str.trim();
    }

    /**
     *字符串去空格
     * 
     * @param str
     * @return
     */
    public static String trimToNull(String str)
    {
      String ts = trim(str);
      return isEmpty(ts) ? null : ts;
    }
    
    /**
     *验证字符串是否为空
     * 
     * @param str
     * @return
     */
    public static boolean isEmpty(String str)
    {
      return (str == null) || (str.length() == 0);
    }
}
